package o;

import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean;
import com.huawei.appgallery.serverreqkit.api.bean.startup.StartupResponse$OOBEAppInfo;
import com.huawei.appgallery.serverreqkit.api.listener.IServerCallBack;
import com.huawei.appmarket.service.apppermission.bean.DownloadPermissionResponse;
import com.huawei.appmarket.service.apppermission.bean.DownloadPermissionResponse.AppPermissionInfo;
import com.huawei.appmarket.service.apppermission.bean.GroupPermissionInfo;
import com.huawei.appmarket.service.apppermission.bean.PermissionInfo;
import com.huawei.appmarket.service.apppermission.bean.SingleAppPermissionInfo;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class dlg {

    public interface e {
        void ˋ(int i);

        void ˎ();
    }

    public static void ˊ(List<StartupResponse$OOBEAppInfo> list, final e eVar) {
        if (CollectCheck.isEmpty(list)) {
            Logger.ˎ("OOBE", "OOBEAppPermissionManager: requireList is empty");
            return;
        }
        Logger.ˎ("OOBE", "OOBEAppPermissionManager:start get AppPermissions by Store");
        StringBuilder stringBuilder = new StringBuilder();
        int size = list.size() - 1;
        for (int i = 0; i < size; i++) {
            stringBuilder.append(((StartupResponse$OOBEAppInfo) list.get(i)).ˎ()).append(',');
        }
        stringBuilder.append(((StartupResponse$OOBEAppInfo) list.get(size)).ˎ());
        cvt o_dtl = new dtl(stringBuilder.toString());
        o_dtl.targetServer = "server.store";
        o_dtl.setBlockIfProtocolNotAgreed(false);
        cfw.ˎ(o_dtl, new IServerCallBack() {
            public void prePostResult(BaseRequest o_cvu, ResponseBean responseBean) {
            }

            public void notifyResult(BaseRequest o_cvu, ResponseBean responseBean) {
                if (responseBean.getResponseCode() == 0 && responseBean.getRtnCode_() == 0) {
                    DownloadPermissionResponse downloadPermissionResponse = (DownloadPermissionResponse) responseBean;
                    if (downloadPermissionResponse.ॱ() == null || downloadPermissionResponse.ॱ().isEmpty()) {
                        Logger.ˎ("OOBE", "OOBEAppPermissionManager:Permission is null or empty");
                        if (eVar != null) {
                            eVar.ˎ();
                            return;
                        }
                        return;
                    }
                    dld.ˎ().ॱ().clear();
                    dld.ˎ().ॱ().addAll(downloadPermissionResponse.ॱ());
                    Logger.ˎ("OOBE", "OOBEAppPermissionManager:Get Permissions Success");
                    if (eVar != null) {
                        eVar.ˎ();
                        return;
                    }
                    return;
                }
                Logger.ˎ("OOBE", "OOBEAppPermissionManager:call store failed:" + responseBean.getRtnCode_());
                if (eVar != null) {
                    eVar.ˋ(responseBean.getResponseCode());
                }
            }
        });
    }

    public static ArrayList<SingleAppPermissionInfo> ˎ(List<AppPermissionInfo> list, List<StartupResponse$OOBEAppInfo> list2) {
        ArrayList<SingleAppPermissionInfo> arrayList = new ArrayList();
        for (AppPermissionInfo appPermissionInfo : list) {
            ˏ(appPermissionInfo, ˊ(appPermissionInfo, ˎ(arrayList, appPermissionInfo, list2)));
        }
        return arrayList;
    }

    private static void ˏ(AppPermissionInfo appPermissionInfo, GroupPermissionInfo groupPermissionInfo) {
        List ˏ = groupPermissionInfo.ˏ();
        if (ˏ == null) {
            ˏ = new ArrayList();
            groupPermissionInfo.ˎ(ˏ);
        }
        ˏ.add(new PermissionInfo(appPermissionInfo.ॱ(), appPermissionInfo.ˋ()));
    }

    private static GroupPermissionInfo ˊ(AppPermissionInfo appPermissionInfo, SingleAppPermissionInfo singleAppPermissionInfo) {
        List ॱ = singleAppPermissionInfo.ॱ();
        List list;
        if (ॱ == null) {
            ॱ = new ArrayList();
            singleAppPermissionInfo.ˊ(ॱ);
            list = ॱ;
        } else {
            list = ॱ;
        }
        for (GroupPermissionInfo groupPermissionInfo : r1) {
            if (groupPermissionInfo.ˎ() != null && groupPermissionInfo.ˎ().equals(appPermissionInfo.ˋ())) {
                break;
            }
        }
        GroupPermissionInfo groupPermissionInfo2 = null;
        if (groupPermissionInfo2 != null) {
            return groupPermissionInfo2;
        }
        groupPermissionInfo2 = new GroupPermissionInfo(appPermissionInfo.ˋ());
        r1.add(groupPermissionInfo2);
        return groupPermissionInfo2;
    }

    private static SingleAppPermissionInfo ˎ(ArrayList<SingleAppPermissionInfo> arrayList, AppPermissionInfo appPermissionInfo, List<StartupResponse$OOBEAppInfo> list) {
        SingleAppPermissionInfo singleAppPermissionInfo;
        Iterator it = arrayList.iterator();
        while (it.hasNext()) {
            singleAppPermissionInfo = (SingleAppPermissionInfo) it.next();
            if (singleAppPermissionInfo.ˊ().equals(appPermissionInfo.ˊ())) {
                break;
            }
        }
        singleAppPermissionInfo = null;
        if (singleAppPermissionInfo != null) {
            return singleAppPermissionInfo;
        }
        String ˏ;
        String str = "";
        for (StartupResponse$OOBEAppInfo startupResponse$OOBEAppInfo : list) {
            if (startupResponse$OOBEAppInfo.ˎ().equals(appPermissionInfo.ˊ())) {
                ˏ = startupResponse$OOBEAppInfo.ˏ();
                break;
            }
        }
        ˏ = str;
        SingleAppPermissionInfo singleAppPermissionInfo2 = new SingleAppPermissionInfo(appPermissionInfo.ˊ(), ˏ);
        arrayList.add(singleAppPermissionInfo2);
        return singleAppPermissionInfo2;
    }
}
